package com.sitc.administrator.application.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;

import com.google.gson.Gson;
import com.sitc.administrator.application.R;
import com.sitc.administrator.application.datasource.Orm;
import com.sitc.administrator.application.datasource.SharedPreferencesUtil;
import com.sitc.administrator.application.util.StaticValue;

import java.util.HashMap;
import java.util.Map;


public class BaseActivity extends AppCompatActivity implements View.OnClickListener{
    private ProgressDialog progressDialog;

    public SharedPreferencesUtil getSp() {
        return sp;
    }

    protected SharedPreferencesUtil sp;
    protected Orm orm;

    public Gson getGs() {
        return gs;
    }

    protected Gson gs;
    protected Map<String, String> params;
    protected String defaultWebcfg;
    /**
     * 找控件
     */
    protected void initViews() {
    }

    /**
     *设置数据
     */
    protected void initDatas() {

    }

    /**
     * 绑定监听器
     */
    protected void initListener() {

    }

    /**
     * 绑定监听器
     */
    protected void initComplete() {

    }


    private void init() {

        sp = SharedPreferencesUtil.getInstance(getApplicationContext());
        orm = Orm.getInstance(getApplicationContext());
        gs = new Gson();
        params = new HashMap<String, String>();


        //Map<String, String> cfg = new HashMap<String, String>();


        initViews();
        initDatas();
        initListener();
        initComplete();
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        init();
    }
    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        init();
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(view, params);
        init();
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();

    }


    protected void startActivity(Class<?> clazz) {
        startActivity(new Intent(getActivity(),clazz));
    }

    protected void startActivityAfterFinishThis(Class<?> clazz) {
        startActivity(new Intent(getActivity(),clazz));
        finish();
    }

    protected void startActivityExtraId(Class<?> clazz, String id) {
        Intent intent = new Intent(getActivity(), clazz);
        intent.putExtra(StaticValue.ID,id);
        startActivity(intent);
    }

    protected void startActivityExtraString(Class<?> clazz, String string) {
        Intent intent = new Intent(getActivity(), clazz);
        intent.putExtra(StaticValue.STRING,string);
        startActivity(intent);
    }

    protected BaseActivity getActivity() {
        return this;
    }

    public void showLoading() {
        showLoading();
    }

    public void showLoading(String message) {

    }

    public void showLoading(int resId) {
        showLoading(getResources().getString(resId));
    }

    public void hideLoading() {

    }

    @Override
    public void onClick(View v) {

    }


    protected void onTheme() {

        sp = SharedPreferencesUtil.getInstance(getApplicationContext());
        String value="";
        value = sp.get("__AppTheme");

        if(value.equals("1")){
            setTheme(R.style.AppTheme);
        }else if(value.equals("2")){
            setTheme(R.style.AppTheme_2);
        }else if(value.equals("3")){
            setTheme(R.style.AppTheme_3);
        }else if(value.equals("4")){
            setTheme(R.style.AppTheme_4);
        }else {
            setTheme(R.style.AppTheme_2);
            sp.put("__AppTheme","2");
        }



    }




}
